package com.webserver.core;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ClientHandler implements Runnable{
    private Socket socket;

    public ClientHandler(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            InputStream in=socket.getInputStream();
            char pre='a',cur='a';
            StringBuilder builder=new StringBuilder();
            int d;
            while ((d=in.read())!=-1){
                cur=(char)d;
                if (pre==13&&cur==10){break;}
                builder.append(cur);
                pre=cur;

            }
            String line=builder.toString().trim();
            System.out.println(line);

            //获取相关信息
            String method;//请求方式
            String uri;//抽象路径
            String protocol;//协议版本

            String[] array=line.split("\\s");
            method=array[0];
            uri=array[1];
            protocol=array[2];

            System.out.println(method);
            System.out.println(uri);
            System.out.println(protocol);




        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
